#include "standard.h"
#include "ui_standard.h"
#include <QButtonGroup>
#include <QDebug>

#include <QLineEdit>

standard::standard(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::standard)
{
    ui->setupUi(this);
//    this->setFixedSize(1081, 765);
    this->setWindowTitle("标准品设置");
    this->setWindowFlags(this->windowFlags() &~ Qt::WindowMinMaxButtonsHint);

    /* 设置文本框为只读 */
    /* 孔位计算文本框 */
    ui->showCount->setReadOnly(true);
    /* 选择的孔位文本框 */
    ui->textEdit->setReadOnly(true);

    /* 标准品文本框校验 */
    /* 点数 */
    QRegExp countLinerx("100|^[1-9][0-9]{0,1}$");
    QRegExpValidator *countLineReg = new QRegExpValidator(countLinerx, this);
    ui->countLine->setValidator(countLineReg);
    /* 复制品 */
    QRegExp copyLinerx("100|^[1-9][0-9]{0,1}$");
    QRegExpValidator *copyLineReg = new QRegExpValidator(copyLinerx, this);
    ui->copyLine->setValidator(copyLineReg);
    /* 起始定量值 */
    ui->startLine->setValidator(new QDoubleValidator(0, 999999999999999999999999999.9, 1, this));

    ui->tableWidget->verticalHeader()->setDefaultSectionSize(100);
    ui->tableWidget->horizontalHeader()->setDefaultSectionSize(75);

    QButtonGroup * BtnGroupA = new QButtonGroup();
    QButtonGroup * BtnGroupB = new QButtonGroup();

    BtnGroupA->addButton(ui->radioBtn_1, 0);
    BtnGroupA->addButton(ui->radioBtn_2, 1);
    BtnGroupA->setExclusive(true);

    BtnGroupB->addButton(ui->radioBtn_3, 0);
    BtnGroupB->addButton(ui->radioBtn_4, 1);
    BtnGroupB->setExclusive(true);

    ui->radioBtn_1->setChecked(true);
    ui->radioBtn_3->setChecked(true);

    ui->tableWidget->setVerticalHeaderLabels(QStringList() << "A" << "B" << "C" << "D" << "E" << "F" << "G" << "H");

    ui->tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);

    /* 设置起始值为0或为空的校验 */
    connect(ui->startLine, &QLineEdit::editingFinished, this, [=](){
       if(ui->startLine->displayText().toDouble() < 0.1){
            ui->startLine->setText("0.1");
       }
       else if(ui->startLine->displayText().toDouble() > 99.9) {
            ui->startLine->setText("99.9");
       }
       else {
           ui->startLine->setText(QString::number(ui->startLine->displayText().toDouble()));
       }

    });
    connect(ui->startLine, &QLineEdit::textChanged, this, [=](){
        if(ui->startLine->displayText() == ""){
            ui->startLine->setText("0.1");
            ui->startLine->selectAll();
        }
    });

    /* 设置点数为空校验 */
    connect(ui->countLine, &QLineEdit::textChanged, this, [=](){
       if(ui->countLine->displayText() == ""){
           ui->countLine->setText("5");
       }
    });
    /* 设置复制品校验 */
    connect(ui->copyLine, &QLineEdit::textChanged, this, [=](){
       if(ui->copyLine->displayText() == ""){
           ui->copyLine->setText("3");
       }
    });

    connect(ui->exit, &QPushButton::clicked, this, [=](){
        this->close();
    });



}

standard::~standard()
{
    delete ui;
}


